package com.qianbao.controller.v1.bindcard;


import com.qianbao.components.excepion.CommonException;
import com.qianbao.components.svresut.Result;
import com.qianbao.components.svversion.ApiVersion;
import com.qianbao.domain.bindcard.BankCardEntity;
import com.qianbao.service.bindcard.BindCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Controller
@ApiVersion(1)
@RequestMapping("/bindcard/{version}/")
public class BindBankCardController {


    @Autowired
    private BindCardService service;


    @RequestMapping("/add-bank-card")
    @ResponseBody
    public Result addBankCard(@Valid BankCardEntity entity){

        try {
            service.insertCardInfomation(entity);
            return Result.success(Collections.emptyMap());
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }


    @RequestMapping("/find-bank-card-list")
    @ResponseBody
    public Result findCardList(String customId){
        try {
            List<BankCardEntity> entityList = service.findAllBankCard(customId);
            HashMap<String,List> map = new HashMap<>();
            map.put("list",entityList);
            return Result.success(map);
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }






}
